package middleware

import (
	"log"
	"time"

	"mygin/pkg/response"
	"net/http"

	"github.com/gin-gonic/gin"
)

func LoggerMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		start := time.Now()

		// 记录日志
		log.Printf(
			"[%s] %s %s %d %s  %s",
			c.Request.Method,
			c.Request.URL.Path,
			c.ClientIP(),
			c.Writer.Status(),
			time.Since(start),
			"ok",
		)
		c.JSON(http.StatusOK, response.Fail(500, "错误11信息"))
		c.Abort()
		//return
		// 处理请求
		c.Next()
	}
}
